package com.yesep.learn.design.structural.composite;

/**
 * 实现 Leaf 类
 */
public class File implements IFileSystemComponent {
    private String name;

    public File(String name) {
        this.name = name;
    }

    @Override
    public void add(IFileSystemComponent component) {
        // 文件不能包含子组件
        throw new UnsupportedOperationException("Cannot add to a file.");
    }

    @Override
    public void remove(IFileSystemComponent component) {
        // 文件不能包含子组件
        throw new UnsupportedOperationException("Cannot remove from a file.");
    }

    @Override
    public IFileSystemComponent getChild(int index) {
        // 文件不能包含子组件
        throw new UnsupportedOperationException("Cannot get child from a file.");
    }

    @Override
    public void display(int depth) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < depth; i++) {
            sb.append("-");
        }
        System.out.println(sb.toString() + "File: " + name);
    }
}